# for 循环计数
counter = 0

for i in range(10):
    counter += 1

print(counter)
print("----------")

# while循环计数
counter = 0
x = 10

while True:
    if counter == x:
        break
    print(f"sim statement:{counter}")
    counter += 1
print("----------")

# while 循环实现斐波那契函数
a, b = 0, 1
print(a)
while b < 100:
    print(b)
    a, b = b, a + b
print("-------------")

# for 循环实现斐波那契函数
a, b = 0, 1
print(a)
for i in range(20):
    if b > 100:
        break
    else:
        print(b)
    a, b  = b, a + b

print("-------------")
# 第2周第1节课后作业
# 1.加法

def add(x, y):
    return x + y


# 2.减法
def sub(x, y):
    return x - y


# 3.乘法
def mul(x, y):
    return x * y


# 4.除法/抛出自定义异常
class ParamsError():
    pass

def divide(x, y):
    try:
        return x / y
    except ZeroDivisionError:
        raise ParamsError("分母不能为0")


# 5.整除
class ParamsError():
    pass

def double_div(x, y):
    try:
        return x // y
    except ZeroDivisionError:
        raise ParamsError("分母不能为0")


# 6.取余
class ParamsError():
    pass

def surplus(x, y):
    try:
        return x % y
    except ZeroDivisionError:
        raise ParamsError("分母不能为0")


# 7.开方
def sqrt(x):
    return x ** (1/2)



if __name__ == "__main__":

    result1 = add(2, 3)
    print("(2 + 3) = ",result1)

    result2 = sub(5, 2)
    print("(5 - 2) = ",result2)

    result3 = mul(4, 6)
    print("(4 * 6) = ",result3)

    result4 = divide(6, 1)
    print("(6 / 1) = ",result4)

    result5 = double_div(5, 2)
    print("(5 // 2 ) = ",result5)

    result6 = surplus(5, 2)
    print("(5 & 2) = ",result6)

    result7 = sqrt(36)
    print("(36开方) = ",result7)